{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1404
  Verdict: Accepted
}
uses SysUtils, Math;
 
const
	eps:double=1e-6;
 
type
	person=record
		s,n,b:string;
		c:longint;
		l:char;
	end;
 
var
	i,n,ls:longint;
	s:string;
	a:array[0..1010] of person;
 
procedure sort(l,r:longint);
var 
	i,j:longint;
	x,y:person;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
	while (a[i].c<x.c) or ((a[i].c=x.c) and (a[i].l<x.l)) or ((a[i].c=x.c) 
		and (a[i].l=x.l) and (a[i].s<x.s)) do inc(i);
	while (a[j].c>x.c) or ((a[j].c=x.c) and (a[j].l>x.l)) or ((a[j].c=x.c) 
		and (a[j].l=x.l) and (a[j].s>x.s)) do dec(j);
	if i<=j then begin
		y:=a[i];
		a[i]:=a[j];
		a[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
readln(n);
for i:=1 to n do begin
	readln(a[i].s);
	readln(a[i].n);
	readln(s);
	ls:=length(s);
	a[i].l:=s[ls];
	delete(S,ls,1);
	a[i].c:=strtoint(s);
	readln(a[i].b);
end;
sort(1,n);
for i:=1 to n do
	writeln(a[i].c,a[i].l,' ',a[i].s,' ',a[i].n,' ',a[i].b);
end.